package org.iteam.xlz.core.service.base;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

import org.iteam.commons.utils.DateUtil;
import org.iteam.core.utils.SqlBuilder;
import org.iteam.db.BaseService;
import org.iteam.xlz.core.entity.base.ColumnInfo;
import org.iteam.xlz.core.entity.base.ColumnType;

public class ColumnTypeService extends BaseService<ColumnType>{
	private ColumnTypeService(){}
	
	private static ColumnTypeService instance;
	
	public static ColumnTypeService getInstance(){
		if(null==instance){
			instance=new ColumnTypeService();
		}
		return instance;
	}
	
	public long counts(){
		try {
			return super.counts("select count(1) from colum_type where 1=1");
		} catch (SQLException e) {
			e.printStackTrace();
			return 0;
		}
	}
	
	public List<ColumnType> query(long page,long rows){
		try {
			return super.query("select * from colum_type where 1=1 limit ?,?",(page-1)*rows,rows);
		} catch (SQLException e) {
			e.printStackTrace();
			return new ArrayList<ColumnType>();
		}
	}
	
	
	public ColumnType findOne(String id){
		try {
			return super.show("select * from colum_type where 1=1 and id=?",id);
		} catch (SQLException e) {
			e.printStackTrace();
			return new ColumnType();
		}
	}
	
	
	public boolean create(ColumnType model){
		SqlBuilder sql=SqlBuilder.createInsert("colum_type");
		sql.addField("name",model.getName());
		sql.addField("descb",model.getDescb());
		sql.addField("creatTime",DateUtil.currentTime());
		sql.addField("creator",model.getCreator());
		try {
			return super.updates(sql.getSql(),sql.getParams())==1;
		} catch (SQLException e) {
			e.printStackTrace();
			return false;
		}
	}
	
	public boolean update(ColumnType model){
		SqlBuilder sql=SqlBuilder.createUpdate("colum_type");
		sql.addField("name",model.getName());
		sql.addField("descb",model.getDescb());
		sql.addWhere("id",model.getId());
		try {
			return super.updates(sql.getSql(),sql.getParams())==1;
		} catch (SQLException e) {
			e.printStackTrace();
			return false;
		}
	}
	
	public List<ColumnType> getTypeList(){
		try {
			return super.query("select * from colum_type where 1=1");
		} catch (SQLException e) {
			e.printStackTrace();
			return new ArrayList<ColumnType>();
		}
	}
	
	public boolean delete(String id){
		try {
			return super.updates("delete from colum_type where id=?",id)>0;
		} catch (SQLException e) {
			e.printStackTrace();
			return false;
		}
	}
}
